/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package test;

import java.util.ArrayList;

/**
 *
 * @author steely
 */
public class BuildBackend {
    
    public static ArrayList<Shipyard> calculate(ArrayList<Shipyard> shipyards, int amount) {
        Shipyard shipyardToUse = shipyards.get(0);
        for(int i=0;i<amount;i++) {
            for (Shipyard shipyard : shipyards) {
                if(shipyardToUse == shipyard) {
                    shipyardToUse = shipyard;
                } else {
                    shipyardToUse = shipyardToUse.getTotalBuildTime() <= shipyard.getTotalBuildTime() ? shipyardToUse : shipyard;
                }
            }
            shipyardToUse.buildAnother();
        }
        
        return shipyards;
    }
}
